home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / a56 / examples / reverb.a56 < prev    next >
Text File  |  1995-04-27  |  8KB  |  312 lines

  1. ;***************************************************************
  2. ; A stereo reverb for the DSP56001 signal processor.
  3. ; Developed by Quinn Jensen (jensenq@qcj.icon.com) using
  4. ; Dr. Vercoe and company's csound code as a reference for the 
  5. ; configuration and gain values.
  6. ;     NOTE - A much improved reverb algorithm is in sixcomb.a56
  7. ; This program fragment implements a stereo reberb effect
  8. ; on a DSP56001 processor.  The "depth" and wet/dry mix are
  9. ; adjustable.  The following filter configuration is employed:
  10. ;
  11. ;
  12. ;  Left in ------+------- "dry" gain -----------> sum -----> Left out
  13. ;                |                                 ^
  14. ;                v                                 |
  15. ;               sum --> reverb --> "wet" gain -----+
  16. ;                ^                                 |
  17. ;                |                                 v -
  18. ;  Right in -----+------- "dry" gain -----------> sum -----> Right out
  19. ;
  20. ;
  21. ; Note that the reverb path output is negated before summing with the
  22. ; right input signal.  This throws in 180 degrees of phase shift
  23. ; making for interesting results even with mono inputs 
  24. ; (i.e. Left in == Right in).
  25. ; The reverb element looks like this:
  26. ;
  27. ;
  28. ; Input ----+-----> comb1 ------+
  29. ;           |                   |
  30. ;           +-----> comb2 ---\  v
  31. ;           |                  sum -----> allpass1 --> allpass2 ---> output
  32. ;           +-----> comb3 ---/  ^
  33. ;           |                   |
  34. ;           +-----> comb4 ------+
  35. ;
  36. ; Each comb stage looks like this:
  37. ;
  38. ;                        +---- gain <-----+
  39. ;                        |                |
  40. ;                        v                |
  41. ; Input ---> gain ----> sum ---> delay ---+--> out
  42. ;
  43. ;
  44. ; The allpass stages look like:
  45. ;
  46. ;                         +--------- gain <---------+
  47. ;                         |                         |
  48. ;                         v                         |
  49. ; Input ---> gain --+--> sum ---> delay ---> sum ---+----> out
  50. ;                   |                         ^
  51. ;                   |                         |
  52. ;                   +--------> gain ----------+
  53. ;
  54. ; or,
  55. ;
  56. ;                             +-------> gain ----+
  57. ;                             |                  |
  58. ;                             |                  v
  59. ; Input ---> gain ----> sum --+--> delay --+--> sum -----> out
  60. ;                        ^                 |
  61. ;                        |                 |
  62. ;                        +----- gain <-----+
  63. ;
  64. ;
  65. ; I've seen both configurations in the literature, so I plotted the
  66. ; Z-transform and they are equivalent in the steady state.  They are indeed
  67. ; all-pass in the steady state but are supposed to have a subtle, discernable
  68. ; effect in "transient" audio signals.
  69. ;
  70. ; I think it could really use a couple more comb stages to fill in some of the 
  71. ; graininess.  The best possible "diffusion" is desired.  By the way, 
  72. ; I'd enjoy seeing any optimizations to the code.
  73. ;
  74.  
  75. ;hardware specific initialization code
  76.  
  77. include "tdsg.a56"
  78.  
  79. ;***************************************************************
  80. ;
  81. ;    Data and constants
  82. ;
  83. ;***************************************************************
  84.  
  85. dot                ;remember where we were in P-space
  86.     org    x:$10        ;put runtime variables in on-chip X-space
  87.  
  88. ; A spreadsheet was used to calculate the following numbers
  89. ;
  90. ; The gain of each feedback stage is given by
  91. ;
  92. ;    feedback gain = exp(delay * ln(.001)/duration)
  93. ;
  94. ; where "delay" is the delay of the comb or allpass stage in seconds,
  95. ; and "duration" is the time in seconds for the reverberated sound
  96. ; to decay to 1/1000 of its original amplitude.
  97. ;
  98.  
  99. ;  Reverb filter lengths and coefficients  
  100. ;  Sun Aug  4 16:36:16 1991    
  101. ;  
  102. ;      Sample rate               32.5520830 kHz      
  103. ;      Reverb duration            4.0000000 s        
  104. ;  
  105. ;  stage    delay(ms)    length        gain    actual
  106. ;  -----------------------------------------------------       
  107. ;  Comb1   29.7000000       967   0.9500031     29.71
  108. ;  Comb2   37.1000000      1208   0.9379399     37.11
  109. ;  Comb3   41.1000000      1338   0.9314831     41.10
  110. ;  Comb4   43.7000000      1423   0.9273101     43.71
  111. ;  All-1    5.0000000       163   0.9914025      5.01
  112. ;  All-2    1.7000000        55   0.9970685      1.69
  113.  
  114. in_atten equ                      0.3409091
  115. comb_atten equ                    0.0416667
  116. dry_init equ                      0.4000000    ; initial "dry" gain
  117. reverb_init equ                0.9900000    ; initial "wet" gain
  118.  
  119. ; comb 1 data and parameters
  120.  
  121. c1d equ                   $4000
  122. c1r  dc                     c1d
  123. c1m equ                     966
  124. c1c equ                           0.9500031
  125.  
  126. ; comb 2 data and parameters
  127.  
  128. c2d equ          c1d+      2048
  129. c2r  dc                     c2d
  130. c2m equ                    1207
  131. c2c equ                           0.9379399
  132.  
  133. ; comb 3 data and parameters
  134.  
  135. c3d equ          c2d+      2048
  136. c3r  dc                     c3d
  137. c3m equ                    1337
  138. c3c equ                           0.9314831
  139.  
  140. ; comb 4 data and parameters
  141.  
  142. c4d equ          c3d+      2048
  143. c4r  dc                     c4d
  144. c4m equ                    1422
  145. c4c equ                           0.9273101
  146.  
  147. ; allpass 1 data and parameters
  148.  
  149. a1d equ          c4d+      2048
  150. a1r  dc                     a1d
  151. a1m equ                     162
  152. a1c equ                           0.9914025
  153.  
  154. ; allpass 2 data and parameters
  155.  
  156. a2d equ          a1d+      2048
  157. a2r  dc                     a2d
  158. a2m equ                      54
  159. a2c equ                           0.9970685
  160.  
  161.     org    y:$0
  162.  
  163. reverb_on equ    reverb_init
  164. reverb_off equ    0
  165.  
  166. reverb_gain
  167.     dc    reverb_on
  168. dry_gain
  169.     dc    dry_init
  170.  
  171.     org    p:dot        ;go back to P-space
  172.  
  173. ;*****************************************************
  174. ;
  175. ; reverb initialization code
  176. ;
  177. ;*****************************************************
  178.  
  179. hf_init
  180.     rts
  181.  
  182. ;*****************************************************
  183. ;
  184. ; run-time controls
  185. ;
  186. ;*****************************************************
  187.  
  188. eff1_on        ;enable reverb
  189.     move            #reverb_on,y0
  190.     move            y0,y:<reverb_gain
  191.     rts
  192.  
  193. eff1_off    ;bypass reverb
  194.     move            #reverb_off,y0
  195.     move            y0,y:<reverb_gain
  196.     rts
  197.  
  198. ;*****************************************************
  199. ;
  200. ; interrupt time calculations
  201. ;
  202. ;*****************************************************
  203.  
  204. ;
  205. ; fs = 32.552083 kHz
  206. ;
  207.  
  208. hf_comp
  209.     jsr    <saveregs
  210. ;
  211. ;    L/R mix
  212. ;
  213.     clr    a    #in_atten,x1        ;clr a, get scale for mix
  214.     move        x:<in_l,x0        ;get left in
  215.     move        x0,x:<in_ls        ;save
  216.     macr    x0,x1,a x:<in_r,x0        ;a = scale * left, get right
  217.     macr    x0,x1,a    x0,x:<in_rs        ;a += scale * right, save right
  218.     clr    b        a,y0        ;y0 goes to the combs, b is sum
  219. ;
  220. ;    comb 1 
  221. ;
  222.     move        x:<c1r,r0
  223.     movec        #c1m,m0
  224.     move            y0,a
  225.     move        x:(r0),x1
  226.     add    x1,b    #c1c,x0
  227.     macr    x0,x1,a
  228.     move        a,x:(r0)+
  229.     move        r0,x:<c1r
  230. ;
  231. ;    comb 2
  232. ;
  233.     move        x:<c2r,r0
  234.     movec        #c2m,m0
  235.     move            y0,a
  236.     move        x:(r0),x1
  237.     add    x1,b    #c2c,x0
  238.     macr    x0,x1,a
  239.     move        a,x:(r0)+
  240.     move        r0,x:<c2r
  241. ;
  242. ;    comb 3
  243. ;
  244.     move        x:<c3r,r0
  245.     movec        #c3m,m0
  246.     move            y0,a
  247.     move        x:(r0),x1
  248.     add    x1,b    #c3c,x0
  249.     macr    x0,x1,a
  250.     move        a,x:(r0)+
  251.     move        r0,x:<c3r
  252. ;
  253. ;    comb 4
  254. ;
  255.     move        x:<c4r,r0
  256.     movec        #c4m,m0
  257.     move            y0,a
  258.     move        x:(r0),x1
  259.     add    x1,b    #c4c,x0
  260.     macr    x0,x1,a
  261.     move        a,x:(r0)+
  262.     move        r0,x:<c4r
  263. ;
  264. ;    scale
  265. ;
  266.     move        #comb_atten,x0    b,y0
  267.     mpyr    x0,y0,b
  268.  
  269. ;
  270. ;    allpass 1
  271. ;
  272.     move        x:<a1r,r0
  273.     movec        #a1m,m0
  274.     move        #a1c,x0
  275.     move        x:(r0),x1
  276.     macr    x0,x1,b    x1,a
  277.     move            b,y0
  278.     macr    -x0,y0,a b,x:(r0)+
  279.     move        r0,x:<a1r
  280. ;
  281. ;    allpass 2
  282. ;
  283.     move        x:<a2r,r0
  284.     movec        #a2m,m0
  285.     move        #a2c,x0
  286.     move        x:(r0),x1
  287.     macr    x0,x1,a    x1,b
  288.     move            a,y0
  289.     macr    -x0,y0,b a,x:(r0)+
  290.     move        r0,x:<a2r
  291. ;
  292. ;    output mix
  293. ;
  294.     move        b,x0
  295.     move            y:<reverb_gain,y0
  296.     mpyr    x0,y0,b        y:<dry_gain,y0
  297.     move        x:<in_ls,x0
  298.     move        b,a
  299.     macr    x0,y0,a    x:<in_rs,x0
  300.     macr    x0,y0,b    a,x:<out_l
  301.     move        b,x:<out_r
  302.  
  303.     jsr    <restregs
  304.     rts
  305.  
  306.     end
  307.  
  308.